<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!-- 重量段遍历tr(其中价格遍历这tr的td),分区遍历第一个tr的td  -->
<tr>
	<td class="priceTd">重量段说明</td>
	<td class="priceTd">货物类型</td>
	<td class="priceTd">最低重量</td>
	<td class="priceTd">最高重量</td>
	<td class="priceTd">计算方式</td>
	<td class="priceTd">单位重量</td>
	<c:forEach items="${requestScope.epartitionsList}" var="eparttion">
		<td class="priceTd">${eparttion.partition_name}</td>
	</c:forEach>
</tr>
<c:forEach items="${requestScope.prices}" var="price" varStatus="ni">
<tr id="prices${ni.index}">
	<td id="tdsss${ni.index}" class="priceTd"><input id="zld${ni.index}" type="text" name="allPrices[${ni.index}]" value="${price[0]}" class="required" size="5"/></td>
	<td class="priceTd"><select name="allPrices[${ni.index}]" style="width: 70px;"><option value="WPX">包裹</option><option value="DOC">文件</option></select></td>
	<td class="priceTd"><input name="allPrices[${ni.index}]" type="text" value="0.5" class="number required" size="5"/></td>
	<td class="priceTd"><input name="allPrices[${ni.index}]" type="text" value="0.5" class="number required" size="5"/></td>
	<td class="priceTd"><select name="allPrices[${ni.index}]" style="width: 70px;"><option value="1">金额</option><option value="2">单价</option><option value="3">首重价格</option><option value="4">续重价格</option></select></td>
	<td class="priceTd"><input name="allPrices[${ni.index}]" type="text" value="0.5" class="number required" size="5"/></td>
	<c:forEach items="${price}" var="priceLine" begin="1">
		<td class="priceTd2"><input name="allPrices[${ni.index}]" type="text" value="${priceLine}" class="number required" size="5"/></td>
	</c:forEach>
	<input type="hidden" name="allPrices" value="" /><!-- 导入价格需要 -->
</tr>
</c:forEach>
<script type="text/javascript">
	(function(){	//加上onError方法-对IE有效,  大货小货进位标准!! 21以上为大货
		var len = $("#priceTableBody tr").length;// 20 - 19 alert($("#priceTableBody tr:eq("+i+")").attr("id"));
		var shou = -1;	//捕获 '首'的数值,用于编辑'续'的数值
		var zuigao = -1;	//前一个的最高数值
		for(var ia=0;ia<len-1;ia++){
			var zld = $("#zld"+ia).val();	//本行重量段,可用$("#prices"+ia+" td:eq(0) input")代替
			//判断是否大货
			if(parseInt(zld) >= 21){
				$("#prices"+ia+" td:eq(5) input").attr("value",$("#channelBcarry").val());
			}else{
				$("#prices"+ia+" td:eq(5) input").attr("value",$("#channelScarry").val());
			} 
			
			var cc;
			if(zld.indexOf('-') != -1){
				cc = 1;
				$("#prices"+(ia-1)+" td:eq(4) select").attr("value",2);
			}else if( zld.indexOf('以上') != -1){
				cc = 2;
				$("#prices"+(ia-1)+" td:eq(4) select").attr("value",2);
			}else if(zld.indexOf('首') != -1){
				cc = 3;
				$("#prices"+(ia-1)+" td:eq(4) select").attr("value",3);
			}else if(zld.indexOf('续') != -1){
				cc = 4;
				$("#prices"+(ia-1)+" td:eq(4) select").attr("value",4);
			}else if(zld.indexOf('≥') != -1){
				cc = 6;
				$("#prices"+(ia-1)+" td:eq(4) select").attr("value",2);
			}else{
				cc = 5;
				$("#prices"+(ia-1)+" td:eq(4) select").attr("value",1);
			}
			
			if(ia == 0 ){
				//第一行
				switch(cc){
					case 1:
						$("#prices"+ia+" td:eq(2) input").attr("value",zld.substring(0,zld.indexOf('-')));
						$("#prices"+ia+" td:eq(3) input").attr("value",zld.substring(zld.indexOf('-')+1,zld.indexOf('kg')==-1?zld.length:zld.indexOf('kg')));
						zuigao = $("#prices"+ia+" td:eq(3) input").val();	//重复
						break;
					case 2:
						var yishang = zhuanhuan(zld);
						$("#prices"+ia+" td:eq(2) input").attr("value",yishang);
						$("#prices"+ia+" td:eq(3) input").attr("value",9000);
						break;
					case 3:
						shou = zhuanhuan(zld);
						$("#prices"+ia+" td:eq(2) input").attr("value",0);
						$("#prices"+ia+" td:eq(3) input").attr("value",shou);
						$("#prices"+ia+" td:eq(5) input").attr("value",shou);
						zuigao = $("#prices"+ia+" td:eq(3) input").val();	//重复
						break;
					case 5:
						$("#prices"+ia+" td:eq(2) input").attr("value",0);
						$("#prices"+ia+" td:eq(3) input").attr("value",zld);
						zuigao = $("#prices"+ia+" td:eq(3) input").val();	//重复
						break;
					case 6:
						$("#prices"+ia+" td:eq(2) input").attr("value",0);
						$("#prices"+ia+" td:eq(3) input").attr("value",zhuanhuan(zld));
						zuigao = $("#prices"+ia+" td:eq(3) input").val();	//重复
						break;
					}
			}else{
				//非第一行
				switch(cc){
					case 1:
						$("#prices"+ia+" td:eq(2) input").attr("value",zld.substring(0,zld.indexOf('-')));//可能是zuigao
						$("#prices"+ia+" td:eq(3) input").attr("value",zld.substring(zld.indexOf('-')+1,zld.indexOf('kg')==-1?zld.length:zld.indexOf('kg')));
						zuigao = $("#prices"+ia+" td:eq(3) input").val();	//重复
						if($("#prices"+(ia-1)+" td:eq(0) input").val().indexOf('续') != -1){
							//前一个'续'
							$("#prices"+(ia-1)+" td:eq(3) input").attr("value",$("#prices"+ia+" td:eq(2) input").val());
						}
						break;
					case 2:
						var yishang = zhuanhuan(zld);
						$("#prices"+ia+" td:eq(2) input").attr("value",yishang);	//可能是最高
						$("#prices"+ia+" td:eq(3) input").attr("value",9000);
						if($("#prices"+(ia-1)+" td:eq(0) input").val().indexOf('续') != -1){
							//前一个'续'
							$("#prices"+(ia-1)+" td:eq(3) input").attr("value",yishang);
						}
						break;
					case 3:
						shou = zhuanhuan(zld);
						$("#prices"+ia+" td:eq(2) input").attr("value",shou);
						$("#prices"+ia+" td:eq(3) input").attr("value",shou);
						$("#prices"+ia+" td:eq(5) input").attr("value",shou);
						zuigao = $("#prices"+ia+" td:eq(3) input").val();	//重复
						if($("#prices"+(ia-1)+" td:eq(0) input").val().indexOf('首') != -1){
							//前一个'首'是文件
							$("#prices"+(ia-1)+" td:eq(1) select").attr("value","DOC");
						}else if($("#prices"+(ia-1)+" td:eq(0) input").val().indexOf('续') != -1){
							//前一个'续'
							$("#prices"+(ia-1)+" td:eq(3) input").attr("value",shou);
						}
						break;
					case 4:
						$("#prices"+ia+" td:eq(2) input").attr("value",zuigao);
						break;
					case 5:
						$("#prices"+ia+" td:eq(2) input").attr("value",zuigao);
						$("#prices"+ia+" td:eq(3) input").attr("value",zld);
						zuigao = $("#prices"+ia+" td:eq(3) input").val();	//重复
						if($("#prices"+(ia-1)+" td:eq(0) input").val().indexOf('续') != -1){
							//前一个'续'
							$("#prices"+ia+" td:eq(2) input").attr("value",zld-0.5);
							$("#prices"+(ia-1)+" td:eq(3) input").attr("value",zld-0.5);
						}
						break;
					case 6:
						$("#prices"+ia+" td:eq(2) input").attr("value",zuigao);
						$("#prices"+ia+" td:eq(3) input").attr("value",zhuanhuan(zld));
						zuigao = $("#prices"+ia+" td:eq(3) input").val();	//重复
						if($("#prices"+(ia-1)+" td:eq(0) input").val().indexOf('续') != -1){
							//前一个'续'
							$("#prices"+ia+" td:eq(2) input").attr("value",zhuanhuan(zld)-0.5);
							$("#prices"+(ia-1)+" td:eq(3) input").attr("value",zhuanhuan(zld)-0.5);
						}
						break;
				}
			}
		}
	})();
</script>